﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TaskManageDemo.Utility
{
    public class Common
    {
        public static T3 Execute<T1, T2, T3>(Func<T1, T2, T3> predicate, T1 parameter1, T2 parameter2, string msg, params object[] args)
        {
            T3 TVaule = default(T3);
            try
            {
                TVaule = predicate.Invoke(parameter1, parameter2);
            }
            catch (Exception ex)
            {
                var methodName = predicate.Method != null ? predicate.Method.Name : string.Empty;
                Log.Logger.ErrorFormat("{0}{1}{2}", string.Format("『{0}』::", methodName), string.Format(msg, args), string.Format("{0}消息：{1}", msg.EndsWith(",") ? "" : ",", ex.Message));
            }
            return TVaule;
        }

        public static void Execute<T1, T2>(Action<T1, T2> predicate, T1 parameter1, T2 parameter2, string msg, params object[] args)
        {
            try
            {
                predicate.Invoke(parameter1, parameter2);
            }
            catch (Exception ex)
            {
                var methodName = predicate.Method != null ? predicate.Method.Name : string.Empty;
                Log.Logger.ErrorFormat("{0}{1}{2}", string.Format("『{0}』::", methodName), string.Format(msg, args), string.Format("{0}消息：{1}", msg.EndsWith(",") ? "" : ",", ex.Message));
            }
        }
        public static T2 Execute<T1,T2>(Func<T1,T2> predicate, T1 parameter1, string msg, params object[] args)
        {
            T2 TVaule = default(T2);
            try
            {
               TVaule= predicate.Invoke(parameter1);
            }
            catch (Exception ex)
            {
                var methodName = predicate.Method != null ? predicate.Method.Name : string.Empty;
                Log.Logger.ErrorFormat("{0}{1}{2}", string.Format("『{0}』::", methodName), string.Format(msg, args), string.Format("{0}消息：{1}", msg.EndsWith(",") ? "" : ",", ex.Message));
            }
            return TVaule;
        }
    }
}
